package com.ruoyi.syf.controller;

import com.ruoyi.syf.domain.RiskCheckTask;
import com.ruoyi.syf.domain.vo.RiskCheckTaskVo;
import com.ruoyi.syf.service.IRiskCheckTaskService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

/**
 * 排查定时任务
 *
 * @author yr
 * @date 2024-07-31
 */
@RestController
@RequestMapping("/syf/task")
public class RiskCheckTaskController extends BaseController {
    @Autowired
    private IRiskCheckTaskService riskCheckTaskService;

    /**
     * 查询排查定时任务列表
     */
    @GetMapping("/list")
    public AjaxResult list(RiskCheckTask riskCheckTask) {
        return success(riskCheckTaskService.list(riskCheckTask));
    }

    /**
     * 获取排查定时任务详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(riskCheckTaskService.getById(id));
    }

    /**
     * 新增或修改排查定时任务
     */
    @Log(title = "排查定时任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult addOrUpdate(@RequestBody RiskCheckTaskVo vo) throws IllegalAccessException {
        return toAjax(riskCheckTaskService.addOrUpdateTask(vo));
    }

    /**
     * 启动\停止任务
     */
    @Log(title = "排查定时任务", businessType = BusinessType.UPDATE)
    @PutMapping("/upStatus/{id}")
    public AjaxResult upStatus(@PathVariable("id") Long id) throws IllegalAccessException {
        return toAjax(riskCheckTaskService.upStatus(id));
    }

    /**
     * 删除排查定时任务
     */
    @PreAuthorize("@ss.hasPermi('syf:task:remove')")
    @Log(title = "排查定时任务", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id) {
        return toAjax(riskCheckTaskService.deleteById(id));
    }
}
